package com.xlh.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 短信返回值枚举
 * <p>
 * Created by lx on 2020/3/11.
 */
@Getter
@AllArgsConstructor
public enum SmsEnum {

    SUCCESS("0000", "请求成功"),

    INSUFFICIENT_ACCOUNT_BALANCE("0023", "管理者账户余额不足，发送失败，请联系管理员"),
    INSUFFICIENT_ACCOUNT_FREEZE("0066", "管理者账户余额已被冻结，发送失败，请联系管理员"),
    ACCOUNT_DISABLED("0181", "账号已停用，发送失败，请联系管理员"),

    TEL_FORMAT_ERROR("0025", "手机格式不对，发送失败"),
    TEL_NOT_FOUND("0026", "手机号不存在，发送失败"),

    SEND_LIMIT("0098", "手机号超过营销多日发送频次限制"),
    SEND_SECOND_LIMIT("0159","超过每秒发送频率限制"),
    SEND_MINUTE_LIMIT("0174","一分钟内下发短信超过次数限制，发送失败"),
    SEND_HOUR_LIMIT("0141","一小时内发送给单个手机次数超过限制，发送失败"),
    SEND_DAY_LIMIT("0142","24小时内发送给单个手机次数超过限制，发送失败");

    private String code;

    private String message;

    public static SmsEnum getByCode(String code) {
        for (SmsEnum smsEnum : SmsEnum.values()) {
            if (Objects.equals(smsEnum.getCode(), code)) {
                return smsEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(String code) {
        SmsEnum smsEnum = getByCode(code);
        return smsEnum == null ? null : smsEnum.getMessage();
    }

}
